/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


Ext.define('Intranet.Desktop.view.ChangePass', {
    extend: 'Ext.form.Panel',
    
    bodyPadding: 10,
    border: false,
    
    defaultType: 'textfield',
    
    items: [{
                    fieldLabel: 'New Password',
                    name: 'password',
                    inputType: 'password',
                    allowBlank: false,
//                    listeners: {
//                        specialkey: function(field, event) {
//                            if (event.getKey() === event.ENTER) {
//                                var form = field.up('form').getForm();
//                                form.submit();
//                            }
//                        }
//                    }
            }, {
                    fieldLabel: 'Retype New Password',
                    name: 're_password',
                    inputType: 'password',
                    allowBlank: false,
//                    listeners: {
//                        specialkey: function(field, event) {
//                            if (event.getKey() === event.ENTER) {
//                                var form = field.up('form').getForm();
//                                form.submit();
//                            }
//                        }
//                    }
            }],

    buttons: [{
            text: 'Save',
            formBind: true,
            disabled: true,
            handler: function(){
                    
                var form = this.up('form').getForm();
                form.submit({
                    
                    url: '/src/public/user/auth/changePassword',
                    
                    method: 'POST',
                    
                    success: function(form, action) {
                        if(action.result.success === 'true')
                        {
                            var changePass_window = Ext.getCmp('change-pass-window');

                            changePass_window.destroy();
                            
                            Ext.Msg.alert('Change password', action.result.msg);
                        }
                        else
                        {
                            Ext.Msg.alert('Change password failed', action.result.msg);
                        } 
                    },
                            
                    failure: function(form, action) {
                        Ext.Msg.alert('Login failed', 'Error ajax');
                    }

                });
                    
            }
        }, {
                text: 'Cancel',
                handler: function() {
                    this.up('form').getForm().reset();
                }
            }
    ]
    
});




